<?php
/**
 * @since v1.0
 * @modify 2015.6.21
 * @copyright 深圳亿游
 */
require_once(LIB_PATH.'controller/root.con.php');

class bannerCon extends rootCon
{
	/**
	 * 广告列表
	 */
    public function listAction() {
    	//判断缓存是否有数据
        $list = myredis::getArray("bannerList");
        if($list){
            $this->j(0, "cache",$list);
        }

        $obj = new Banner();
        $currentTime = date('Y-m-d H:i:s');
        $result['banner'] = $obj->all("status=".STATUS_PUBLISH." AND onlineTime<='$currentTime' AND  (offlineTime>='$currentTime' OR offlineTime IS NULL)",'weight DESC');
        $i = 0;
        foreach($result['banner'] as $item){
            $result['banner'][$i]['image'] = $this->getHttpImage($item['image']);
            $i++;
        }

        $obj = new HotLeft();
        $currentTime = date('Y-m-d H:i:s');
        $result['hotLeft'] = $obj->all("status=".STATUS_PUBLISH." AND onlineTime<='$currentTime' AND  (offlineTime>='$currentTime' OR offlineTime IS NULL)",'weight DESC');
        $i = 0;
        foreach($result['hotLeft'] as $item){
            $result['hotLeft'][$i]['img'] = $this->getHttpImage($item['img']);
            $i++;
        }

        $obj = new HotRight();
        $currentTime = date('Y-m-d H:i:s');
        $result['hotRight'] = $obj->all("status=".STATUS_PUBLISH." AND onlineTime<='$currentTime' AND  (offlineTime>='$currentTime' OR offlineTime IS NULL)",'weight DESC');
        $i = 0;
        foreach($result['hotRight'] as $item){
            $result['hotRight'][$i]['img'] = $this->getHttpImage($item['img']);
            $i++;
        }

        myredis::setArray("bannerList",$result,600);
        $this->j(0, "db",$result);
    }


    private function getHttpImage($img){
        $reg = "/^http/i";
        if(!preg_match($reg,$img)){
            return FRONT_URL.$img;
        }

        return $img;
    }

}



